<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2007/07/17 06:19:54 $)
// $RCSfile: staff_newticket.php,v $ : $Revision: 1.31 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

if ($_SWIFT["staff"]["t_entab"] == "0")
{
	echo '<font face="Verdana, Arial, Helvetica" size="2" color="red"><b>'.$_SWIFT["language"]["nopermission"].'</b></font>';
	exit;
}

require_once ("./includes/functions_html.php");
$grid = new Grid();
$template->loadLanguageSection("staff_tickets");
$template->loadLanguageSection("tickets_auditlogs");
require_once ("./modules/tickets/functions_ticketsui.php");
require_once ("./modules/tickets/functions_ticketcore.php");
require_once ("./modules/tickets/functions_ticketmain.php");
require_once ("./modules/tickets/functions_newticket.php");
require_once ("./includes/functions_customfields.php");
require_once ("./includes/functions_users.php");
require_once ("./includes/functions_mail.php");


/**
* ###############################################
* NEW TICKET
* ###############################################
*/
if ($eventaction == "newticket")
{
	//Mahesh Slaria: Check for permissions.
	// Varun Shoor: Added t_restrictnewticket setting to toggle this
	$_assigns = getAssignedDepartments();
	if ($_SWIFT["staff"]["tnewticket"] == "0" || ($_SWIFT["settings"]["t_restrictnewticket"] == 1 && !in_array(intval($_REQUEST["departmentid"]), $_assigns))) {
		$errormessage = $_SWIFT["language"]["nopermission"];
	}
	//-----------/
	else if ($_POST["step"] == "1" && $_SWIFT["staff"]["tnewticket"] != 0)
	{
		//Mahesh Slaria: Staff & user ticket creation
		if (trim($_POST["replycontents"]) == "" || trim($_POST["opt_subject"]) == "" || !checkCustomFieldContent(CUSTOMFIELD_STAFFTICKET, $_POST["departmentid"]) ||
		!checkCustomFieldContent(CUSTOMFIELD_STAFFUSERTICKET, $_POST["departmentid"]))
		{
			$errormessage = $_SWIFT["language"]["requiredfieldempty"];
		} else if ($_POST["type"] == "generic" && (empty($_POST["opt_useremail"]))) {
			$errormessage = $_SWIFT["language"]["emailfieldempty"];
		} else if ($_POST["type"] == "generic" && (!isValidEmail($_POST["opt_useremail"]))) {
			$errormessage = $_SWIFT["language"]["invalidemailspecified"];
		} else {
			// Do we have an email queue set?
			if (!empty($_POST["opt_emailqueueid"]))
			{
				$_emailqueue = $_SWIFT["queuecache"]["list"][$_POST["opt_emailqueueid"]];
				$_tgroupid = $_emailqueue["tgroupid"];
			} else {
				$_emailqueue = array();
				$_tgroupid = 1;
			}

			// Lets see if we have an email set for this user?
			if (!empty($_POST["opt_useremail"]))
			{
				$userid = getUserEmail($_POST["opt_useremail"]);
				if (!$userid)
				{
					// No such user, insert a new one
					$usergroupid = $_SWIFT["tgroupcache"][$_tgroupid]["regusergroupid"];
					if (empty($usergroupid))
					{
						$usergroupid = 2;
					}
					$userid = insertUser(true, $_POST["opt_useremail"], substr(buildHash(),0, 8), $usergroupid, LOGINAPI_DEFAULT, 0, $_POST["opt_username"], 0, 0, false, 1, true);
				}
			}

			if (empty($_POST["opt_username"]) && $_POST["type"] == "phone")
			{
				$fullname = $_POST["opt_useremail"]; // Staff creating ticket as client, set full name to email of client
			} else if (!empty($_POST["opt_username"])) {
				$fullname = $_POST["opt_username"];
			} else {
				$fullname = $_SWIFT["staff"]["fullname"]; // Set full name to staff
			}

			if ($_POST["type"] == "phone")
			{
				$posttype = POST_CLIENT;
			} else {
				$posttype = POST_STAFF;
			}

			if ($_POST["emailautoresponder"] == "1" && !empty($_POST["opt_useremail"]))
			{
				$sendautoresponder = true;
			} else {
				$sendautoresponder = false;
			}

			$ticketiddata = createTicket($posttype, $_SWIFT["staff"]["staffid"], $userid, $fullname, $_POST["opt_useremail"], $_POST["opt_subject"], $_POST["replycontents"], 0, $_POST["tt_priorityid"], $_POST["tt_ticketstatusid"], $_POST["departmentid"], $_POST["opt_emailqueueid"], $_SWIFT["language"]["charset"], "", $_tgroupid, false, false, $sendautoresponder, iif(empty($_POST["opt_userphone"])&&$_POST["type"]=="phone", "-1", $_POST["opt_userphone"]));

			$ticketid = $ticketiddata[0];
			$messageid = $ticketiddata[3];

			$_ticketobj =& new TicketMain($ticketid, false);
			$_ticketobj->messageid = $messageid;

			$mailObj = new SWIFT_Mail();

			$cc = $_POST["opt_cc"];
			$bcc = $_POST["opt_bcc"];
			$ccemaillist = $bccemaillist = array();
			if (!empty($cc))
			{
				if (strstr($cc, ","))
				{
					$ccemaillist = explode(",", $cc);
				} else if (isValidEmail($cc)) {
					$ccemaillist = array($cc);
				}
				if ($_POST["ccaddrecipients"] == "1")
				{
					$_ticketobj->addRecipients($ccemaillist, RECIPIENT_CCUSER);
				}
			}

			if (!empty($bcc))
			{
				if (strstr($bcc, ","))
				{
					$bccemaillist = explode(",", $bcc);
				} else if (isValidEmail($bcc)) {
					$bccemaillist = array($bcc);
				}
				if ($_POST["bccaddrecipients"] == "1")
				{
					$_ticketobj->addRecipients($bccemaillist, RECIPIENT_BCCUSER);
				}
			}

			if ($_POST["emailcontents"] == "1" && !empty($_POST["opt_useremail"]))
			{
				sendNewTicketEmail($_ticketobj, $mailObj, $_tgroupid, $ticketiddata[1], $_POST["opt_useremail"], $_POST["opt_subject"], $_POST["replycontents"], $_POST["opt_emailqueueid"], $ccemaillist, $bccemaillist);
			}

			//Mahesh Slaria: Double attachment error....
			$_attachmentlist = array();
			$_ticketobj->processPostAttachments($ticketiddata[2], $_POST["opt_downloads"], $mailObj, $_attachmentlist);
			
			if (!empty($_POST["tt_staffid"]))
			{
				$_ticketobj->assignTicket($_POST["tt_staffid"]);
			}
			if (trim($_POST["notecontents"]) != "")
			{
				$_ticketobj->addTicketNote($_POST["notetype"], "0", $_POST["notecontents"]);
			}
			if (!empty($_POST["opt_due"]))
			{
				$_ticketobj->markAsDue(getCalendarDateline($_POST["opt_due"]));
			}

			//Mahesh: Timeworked track....
			if (!empty($_POST["opt_timeworked"]) && is_numeric($_POST["opt_timeworked"]))
			{
				$_ticketobj->addBillingEntry(DATENOW, $_POST["opt_timeworked"], $_POST["opt_timeworked"], $_SWIFT["staff"]["staffid"], "");
			}
			//--------------------

			if ($ticketid)
			{
				updateCustomFields(CUSTOMFIELD_STAFFTICKET, $ticketid, $_POST["departmentid"]);
				//Mahesh Slaria: Staff & user ticket creation
				updateCustomFields(CUSTOMFIELD_STAFFUSERTICKET, $ticketid, $_POST["departmentid"]);
				header("location: index.php?_m=tickets&_a=viewticket&ticketid=".intval($ticketid));
				exit;
			} else {
				$errormessage = $_SWIFT["language"]["newticketfailed"];
			}
		}
	} 

	if (!isset($_SWIFT["departmentcache"][$_REQUEST["departmentid"]]))
	{
		trigger_error($_SWIFT["language"]["invaliddepartment"], E_USER_ERROR);
	}
	$_department = &$_SWIFT["departmentcache"][$_REQUEST["departmentid"]];

	$_assigns = getAssignedDepartments(MODULE_TICKETS);
	renderTicketTree();

	$template->assign("calendar", true);
	$template->assign("spellcheck", true);

	$interface->staffHeader($_SWIFT["language"]["tickets"] ." &gt; ".$_SWIFT["language"]["newticket"], 2);
	$interface->staffNavBar('<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["tickets"].'">'.$_SWIFT["language"]["tickets"].'</a> &raquo; <a href="index.php?_m=tickets&_a=manage&departmentid='. intval($_REQUEST["departmentid"]) .'" title="'.$_SWIFT["departmentcache"][$_REQUEST["departmentid"]]["title"].'">'.$_SWIFT["departmentcache"][$_REQUEST["departmentid"]]["title"].'</a> &raquo; <a href="index.php?_m=tickets&_a=newticket&type='. $_REQUEST["type"] .'&departmentid='. intval($_REQUEST["departmentid"]) .'" title="'.$_SWIFT["language"]["newticket"].'">'.$_SWIFT["language"]["newticket"].'</a>', "", 2);

	printInfoBox($_SWIFT["infomessage"]);
	printErrorBox($errormessage);

	if (!empty($_GET["userid"]))
	{
		$_user = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."users`AS users LEFT JOIN `". TABLE_PREFIX ."useremails` AS useremails ON (users.userid = useremails.userid) WHERE users.userid = '". intval($_REQUEST["userid"]) ."' ORDER BY useremails.useremailid ASC LIMIT 1;");
		if (!empty($_user["userid"]))
		{
			$_POST["opt_username"] = $_user["fullname"];
			$_POST["opt_useremail"] = $_user["email"];
		}
		
	}

	?>
	<script type="text/javascript">
	selectedTab = "newticket";
	</script>
	<?

	printFormStart("newticketform", "index.php", "POST", true);
	echo '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="tborder">'.SWIFT_CRLF;
	echo '<thead><tr>'.SWIFT_CRLF;

	echo '<td class="tcat" width="1" align="left" nowrap><img src="'. $_SWIFT["themepath"] .'space.gif" width="4" height="21"></td>'.SWIFT_CRLF;
	echo '<td class="tcat" align="left" nowrap>'. sprintf($_SWIFT["language"]["dnewticket"], $_department["title"]) .'</td>'.SWIFT_CRLF;
	echo '</tr>'.SWIFT_CRLF;
	echo '</thead>'.SWIFT_CRLF;

	echo '<tbody><tr><td class="contenttableborder" colspan="2"><table border="0" cellpadding="3" cellspacing="1" width="100%">'.SWIFT_CRLF;
	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["from"] .'</span></td>
	<td align="left"><select name="opt_emailqueueid" class="swiftselect">';
	// 1st - Queue Emails
	$firston = true;
	foreach ($_SWIFT["queuecache"]["list"] as $key=>$val)
	{
		if ($val["departmentid"] == $_department["departmentid"])
		{
			if ($firston)
			{
				$seltext = " selected";
				$firston = false;
			}
			$fromname = iif(empty($val["customfromname"]), $_SWIFT["staff"]["fullname"], $val["customfromname"]);
			$fromemail = iif(empty($val["customfromemail"]), $val["email"], $val["customfromemail"]);
			echo '<option value="'. intval($val["emailqueueid"]) .'"'. $seltext .'>'. htmlspecialchars($fromname) .' &lt;'. htmlspecialchars($fromemail) .'&gt;</option>'.SWIFT_CRLF;
		}
	}
	// 2nd - Personal Email
	echo '<option value="0">'. htmlspecialchars($_SWIFT["staff"]["fullname"]) .' &lt;'. htmlspecialchars($_SWIFT["staff"]["email"]) .'&gt;</option>'.SWIFT_CRLF;
	echo '</select></td></tr>';

	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["subject"] .'</span></td>
	<td align="left"><input type="text" class="swifttext" size="40" name="opt_subject" value="'. $_POST["opt_subject"] .'">&nbsp;&nbsp;</td></tr>';

	if ($_REQUEST["type"] == "phone")
	{
		echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["fophone"] .'</span></td>
	<td align="left"><input type="text" class="swifttext" size="40" name="opt_userphone" value="'. $_POST["opt_userphone"] .'">&nbsp;&nbsp;<a href="javascript:popupInfoWindow(\''. $_SWIFT["swiftpath"] .'staff/index.php?_m=core&_a=userlookup&formname=newticketform&formfield=opt_userphone&sessionid='. $_SWIFT["session"]["sessionid"] .'\');"><img src="'. $_SWIFT["themepath"] .'icon_searchlookup.gif" title="'. $_SWIFT["language"]["lookup"] .'" border="0" align="absmiddle" /></a>&nbsp;&nbsp;<span class="smalltext">'. $_SWIFT["language"]["noptional"] .'</span></td></tr>';
		echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["fullname"] .'</span></td>
	<td align="left"><input type="text" class="swifttext" size="40" name="opt_username" value="'. $_POST["opt_username"] .'">&nbsp;&nbsp;<span class="smalltext">'. iif($_REQUEST["type"]=="email", $_SWIFT["language"]["noptional"]) .'</span></td></tr>';
	}

	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["foemail"] .'</span></td>
	<td align="left"><input type="text" class="swifttext" size="40" name="opt_useremail" value="'. $_POST["opt_useremail"] .'">&nbsp;&nbsp;<a href="javascript:popupInfoWindow(\''. $_SWIFT["swiftpath"] .'staff/index.php?_m=core&_a=userlookup&formname=newticketform&formfield=opt_useremail&sessionid='. $_SWIFT["session"]["sessionid"] .'\');"><img src="'. $_SWIFT["themepath"] .'icon_searchlookup.gif" title="'. $_SWIFT["language"]["lookup"] .'" border="0" align="absmiddle" /></a>&nbsp;&nbsp;<span class="smalltext">'. iif($_REQUEST["type"]=="phone", $_SWIFT["language"]["noptional"]) .'</span></td></tr>';


	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left" id="fmenuref"><span class="tabletitle">'. $_SWIFT["language"]["quickinsert"] .'</span></td>
	<td align="left"><a href="#" title="'. $_SWIFT["qpredefinedreplies"] .'" id="fprcachelink" onClick="javascript:CustomPopupRef(\'prcachemenu\', event, \'fprcachelink\', \'prcachemenu\', \'fmenuref\', prmenuloaded);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quickinsert.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qpredefinedreplies"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" title="'. $_SWIFT["qknowledgebase"] .'" id="fkbcachelink" onClick="javascript:CustomPopupRef(\'kbcachemenu\', event, \'fkbcachelink\', \'kbcachemenu\', \'fmenuref\', kbmenuloaded);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quickinsert.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qknowledgebase"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" title="'. $_SWIFT["qdownloads"] .'" id="fdlcachelink" onClick="javascript:CustomPopupRef(\'dlcachemenu\', event, \'fdlcachelink\', \'dlcachemenu\', \'fmenuref\', dlmenuloaded);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quickinsert.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qdownloads"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;</td>
	</tr>';


	unset($_staffoptions); unset($_departmentoptions); unset($_statusoptions); unset($_priorityoptions); unset($_flagoptions);
	$_staffoptions = '<option value="0">'. $_SWIFT["language"]["unassigned"] .'</option>'.SWIFT_CRLF;
	foreach ($_SWIFT["staffcache"] as $key=>$val)
	{
		$_staffoptions .= '<option value="'. intval($val["staffid"]) .'"'. iif($_SWIFT["staff"]["staffid"]==$val["staffid"], " selected") .'>'. htmlspecialchars($val["fullname"]) .'</option>'.SWIFT_CRLF;
	}
	$_staffselect = '<select name="tt_staffid" class="swiftselect">'. $_staffoptions .'</select>'.SWIFT_CRLF;

	$firston = true;
	foreach ($_SWIFT["statuscache"] as $key=>$val)
	{
		$_statusoptions .= '<option value="'. intval($val["ticketstatusid"]) .'" style="color:'. $val["statuscolor"] .'"'. iif($firston==true, " selected") .'>'. htmlspecialchars($val["title"]) .'</option>'.SWIFT_CRLF;
		$firston = false;
	}
	$_statusselect = '<select name="tt_ticketstatusid" class="swiftselect">'. $_statusoptions .'</select>'.SWIFT_CRLF;

	$firston = true;
	foreach ($_SWIFT["prioritycache"] as $key=>$val)
	{
		$_priorityoptions .= '<option value="'. intval($val["priorityid"]) .'" style="background:'. $val["bgcolorcode"] .';color:'. $val["frcolorcode"] .'"'. iif($firston==true, " selected") .'>'. htmlspecialchars($val["title"]) .'</option>'.SWIFT_CRLF;
		$firston = false;
	}
	$_priorityselect = '<select name="tt_priorityid" class="swiftselect">'. $_priorityoptions .'</select>'.SWIFT_CRLF;

	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["properties"] .'</span></td>
	<td align="left">'. $_SWIFT["language"]["qowner"] .$_staffselect.'&nbsp;&nbsp;'. $_SWIFT["language"]["qstatus"] .$_statusselect.'&nbsp;&nbsp;'. $_SWIFT["language"]["qpriority"] .$_priorityselect.'&nbsp;&nbsp;</td>
	</tr>';

	printDescRow($_SWIFT["language"]["contents"]);
	$colarray = array();
	$colarray[0]["align"] = "left";
	$colarray[0]["valign"] = "top";
	$colarray[0]["colspan"] = "2";
	$colarray[0]["nowrap"] = true;
	$colarray[0]["value"] = '<textarea style="WIDTH:100%;" name="replycontents" cols="100" rows="15" tabindex="99" onselect="javascript:storeCaret(this);" onclick="javascript:storeCaret(this);" onkeyup="javascript:storeCaret(this);">'. htmlspecialchars($_POST["replycontents"]) .'</textarea>'.SWIFT_CRLF;
	$colarray[0]["class"] = getRowBG();
	printDataRow($colarray);

	if ($_REQUEST["type"] == "generic")
	{
		$_emailautoresponder = "";
		$_emailcontents = " checked";
	} else {
		$_emailautoresponder = " checked";
		$_emailcontents = "";
	}

	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["options"] .'</span></td>
	<td align="left"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td width="170" nowrap><span class="smalltext">'. $_SWIFT["language"]["pdue"] .'<input type="text" name="opt_due" id="opt_fdue" onclick="return showCalendar(\'opt_fdue\', \''.iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y").'\');" size="12" readonly="1" value="" class="swifttext"/>&nbsp;<img src="'. $_SWIFT["themepath"] .'calendar.gif" id="opt_fduet" onclick="return showCalendar(\'opt_fdue\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y").'\');" style="cursor: pointer;" align="absmiddle"/></span></td><td nowrap><span class="smalltext">'. $_SWIFT["language"]["ptimeworked"] .'<input type="text" name="opt_timeworked" size="12" value="'. $_SWIFT["language"]["inminutes"] .'" onclick="javascript:if(this.value==\''. $_SWIFT["language"]["inminutes"] .'\') { this.value=\'\'; }" class="swifttext"/>&nbsp;
	&nbsp;&nbsp;'. $_SWIFT["language"]["tdispatch"] .' <label for="emailautoresponder"><input type="checkbox" id="emailautoresponder" style="MARGIN: 0px; PADDING: 0px; MARGIN-TOP: 4px;" name="emailautoresponder" value="1"'.$_emailautoresponder.' /> '. $_SWIFT["language"]["tnautores"] .'</label> <label for="emailcontents"><input id="emailcontents" type="checkbox" name="emailcontents" style="MARGIN: 0px; PADDING: 0px; MARGIN-TOP: 4px;" value="1"'.$_emailcontents.' /> '. $_SWIFT["language"]["tncontents"] .'</label></span></td></tr></table>
</td>
	</tr>';

	// ======= ADD NOTE =======
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="fnote1" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["noteoptions"] .'</td>
</tr>
<tr class="row1" title="" onmouseover="" onmouseout="" onclick="" id="fnote2" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan=""><span class="tabletitle">'.$_SWIFT["language"]["notetype"].'</span></td>
<td class="row1" align="left" valign="top" colspan=""><label for="fnotetype[0]"><input type="radio" id="fnotetype[0]" name="notetype" value="'. NOTE_TICKET .'" checked /> <span class="smalltext">'. $_SWIFT["language"]["ticket"] .'</label></span>

<label for="fnotetype[1]"><input type="radio" id="fnotetype[1]" name="notetype" value="'. NOTE_USER .'" /> <span class="smalltext">'. $_SWIFT["language"]["user"] .'</label></span>
</td>
</tr>
<tr class="row2" title="" onmouseover="" onmouseout="" onclick="" id="fnote3" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan="2" width=""><textarea style="WIDTH:100%;" name="notecontents" cols="100" rows="3">'. htmlspecialchars($_POST["notecontents"]) .'</textarea>
</td>
</tr>';

	// ======= ATTACH FILES =======
	$attachrowjs = "switchDisplay('attach0');";
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="attach0" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["attachfile"] .'</td>
</tr>';

$index = 1;
if (empty($_SWIFT["settings"]["t_maxattach"]))
{
	$maxattach = 3;
} else {
	$maxattach = intval($_SWIFT["settings"]["t_maxattach"]);
}

for ($ii=0; $ii<$maxattach; $ii++)
{
	$rowclass = getRowBG();
	$attachrowjs .= "switchDisplay('attach". $index ."');";
	echo '<tr class="'. $rowclass .'" title="" onmouseover="" onmouseout="" onclick="" id="attach'. $index .'" style="DISPLAY: none;">
<td class="'. $rowclass .'" align="left" valign="top" colspan=""><span class="tabletitle">'.sprintf($_SWIFT["language"]["attachfilen"], $index).'</span></td>
<td class="'. $rowclass .'" align="left" valign="top" colspan=""><input type="file" name="opt_file['. $index .']" value="" size="35" class="swifttext" />
</td>
</tr>';
	$index++;
}

	// ======= DOWNLOADS LINK =======
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="fdownloads1" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["qdownloads"] .'</td>
</tr>

<tr class="row1" title="" onmouseover="" onmouseout="" onclick="" id="fdownloads2" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan="2"><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td width="400" align="left"><select name="opt_downloads[]" class="swiftselect" size="5" style="WIDTH: 100%;" multiple></select></td><td align="left" valign="middle"><input type="button" onClick="javascript:removeDLItem();" class="bluebuttonsuperbig" value="'. $_SWIFT["language"]["removefile"] .'" /><BR /><BR /><BR /><input type="button" class="bluebuttonsuperbig" onClick="javascript:clearDLItems();" value="'. $_SWIFT["language"]["cancel"] .'" /></td></tr></table>
</td>
</tr>
';

	// ======= EMAIL OPTIONS =======
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="emailopt1" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["emailoptions"] .'</td>
</tr>

<tr class="row1" title="" onmouseover="" onmouseout="" onclick="" id="emailopt2" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan=""><span class="tabletitle">'.$_SWIFT["language"]["eocc"].'</span></td>
<td class="row1" align="left" valign="top" colspan=""><input type="text" name="opt_cc" value="" size="35" class="swifttext" />&nbsp;&nbsp;( <span class="smalltext"><label for="ccaddrecpients"><input type="checkbox" id="ccaddrecpients" name="ccaddrecipients" value="1" /> '. $_SWIFT["language"]["addtorecp"] .'</label> )</span>&nbsp;&nbsp;<a href="javascript:popupInfoWindow(\''. $_SWIFT["swiftpath"] .'staff/index.php?_m=core&_a=userlookup&formname=replyform&formfield=opt_cc&sessionid='. $_SWIFT["session"]["sessionid"] .'\');"><img src="'. $_SWIFT["themepath"] .'icon_searchlookup.gif" title="'. $_SWIFT["language"]["lookup"] .'" border="0" align="absmiddle" /></a>
</td>
</tr>
<tr class="row2" title="" onmouseover="" onmouseout="" onclick="" id="emailopt3" style="DISPLAY: none;">
<td class="row2" align="left" valign="top" colspan=""><span class="tabletitle">'.$_SWIFT["language"]["eobcc"].'</span></td>
<td class="row2" align="left" valign="top" colspan=""><input type="text" name="opt_bcc" value="" size="35" class="swifttext" />&nbsp;&nbsp;( <span class="smalltext"><label for="bccaddrecpients"><input type="checkbox" id="bccaddrecpients" name="bccaddrecipients" value="1" /> '. $_SWIFT["language"]["addtorecp"] .'</label> )</span>&nbsp;&nbsp;<a href="javascript:popupInfoWindow(\''. $_SWIFT["swiftpath"] .'staff/index.php?_m=core&_a=userlookup&formname=replyform&formfield=opt_bcc&sessionid='. $_SWIFT["session"]["sessionid"] .'\');"><img src="'. $_SWIFT["themepath"] .'icon_searchlookup.gif" title="'. $_SWIFT["language"]["lookup"] .'" border="0" align="absmiddle" /></a>
</td>
</tr>';

	$data[0]["value"] = '<input type="submit" class="yellowbuttonbig" onClick="javascript:processReplyForm();" value="'. $_SWIFT["language"]["send"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:switchDisplay(\'fnote1\');switchDisplay(\'fnote2\');switchDisplay(\'fnote3\');" class="bluebuttonbig" value="'. $_SWIFT["language"]["addnote"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:'. $attachrowjs .'" class="bluebuttonbig" value="'. $_SWIFT["language"]["attachfile"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:openSpellChecker();" class="bluebuttonbig" value="'. $_SWIFT["language"]["spellcheck"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:switchDisplay(\'emailopt1\');switchDisplay(\'emailopt2\');switchDisplay(\'emailopt3\');" class="bluebuttonsuperbig" value="'. $_SWIFT["language"]["emailoptions"] .'" />'.SWIFT_CRLF;
	$data[0]["align"] = "left";
	$data[0]["colspan"] = 2;
	printDataRow($data);

	echo '</table></td></tr></tbody>'.SWIFT_CRLF;
	echo '<tr><td class="contenttableborder" colspan="2"><table border="0" cellpadding="3" cellspacing="1" width="100%">'.SWIFT_CRLF;
	renderStaffCustomFields(CUSTOMFIELD_STAFFTICKET, $_department["departmentid"]);
	//Mahesh Slaria: Staff & user ticket creation
	renderStaffCustomFields(CUSTOMFIELD_STAFFUSERTICKET, $_department["departmentid"]);
	echo '</table></td></tr></table><BR /> ';
	addHiddenField("_m", "tickets");
	addHiddenField("_a", "newticket");
	addHiddenField("step", "1");
	addHiddenField("departmentid", intval($_department["departmentid"]));
	addHiddenField("type", $_REQUEST["type"]);
	printFormEnd();

	$interface->staffFooter();
}
?>